package com.lgx.right.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lgx.common.exception.DataException;
import com.lgx.common.tree.easyui.TreeModel;
import com.lgx.common.web.Pagination;
import com.lgx.right.dao.IRoleDao;
import com.lgx.right.entity.Role;
import com.lgx.right.service.IRoleService;

/**
 * 
 * @author acer
 *
 */
@Service("roleService")
public class RoleService implements IRoleService {

	@Autowired
	private IRoleDao roleDao;

	public IRoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(IRoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public Role createRole(Role role) throws DataException {
		return this.roleDao.createRole(role);
	}

	public Role updateRole(Role role) throws DataException {
		return this.roleDao.updateRole(role);
	}

	public void deleteRole(Role role) throws DataException {
		this.roleDao.deleteRole(role);
	}

	public void deleteRole(long id) throws DataException {
		this.roleDao.deleteRole(id);
	}

	public Role findRoleById(long id) {
		return this.roleDao.findRoleById(id);
	}

	public List<Role> findRoleList(String sql) {
		return this.roleDao.findRoleList(sql);
	}

	public List<Role> findRoleList(String sql, Object[] params, int pageSize,
			int pageNum) {
		return this.roleDao.findRoleList(sql, params, pageSize, pageNum);
	}

	public Pagination findRolePagination(String sql, Object[] params,
			int pageSize, int pageNum) {
		return this.roleDao.findRolePagination(sql, params, pageSize, pageNum);
	}

	public Pagination findRolePagination(Object[] params, int pageSize,
			int pageNum) {
		return this.roleDao.findRolePagination(params, pageSize, pageNum);
	}

	public void deleteRoles(String[] ids) {
		try {
			this.roleDao.deleteRoles(ids);
		} catch (DataException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据userId查找它的角色
	 * @param userID
	 * @return
	 */
	@Override
	public List<TreeModel> findRoleUserTreeList(long userId) {
		return roleDao.findRoleUserTreeList(userId);
	}

	@Override
	public List<Role> findRoleListByIds(String ids) {
		return this.roleDao.findRoleListByIds(ids);
	}
}
